<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>首页</title>
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
    <!-- import Vue before Element -->
    <script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
    <!-- 引入axios -->
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
    <!-- import JavaScript -->
    <script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
    <style>
        .el-header img {
            vertical-align: middle;
        }

        .el-header a {
            color: #666666;
            text-decoration: none;
        }
        .el-table .cell{
        /*    设置一行显示,超出部分显示省略号*/
            white-space: nowrap;
        }
    </style>
</head>
<body>
<div id="app">
    <el-container>
        <el-header height="150px">
            <div style="width: 1600px;margin: 0 auto">
                <img src="../../../../../../Project/CoolShark/src/main/resources/static/imgs/logo.png" width="300px">
                <a href="">首页</a>
                <el-divider direction="vertical"></el-divider>
                <a href="">热点资讯</a>
                <el-divider direction="vertical"></el-divider>
                <a href="">商家入驻</a>
                <el-divider direction="vertical"></el-divider>
                <a href="">社会招聘</a>
                <el-divider direction="vertical"></el-divider>
                <a href="">校园招聘</a>
                <el-divider direction="vertical"></el-divider>
                <a href="">帮助</a>
                <el-divider direction="vertical"></el-divider>
            </div>
            <div style="background-color: #0aa1ed">
                <el-menu style="width: 1400px ;margin: 0 auto" mode="horizontal"
                         background-color="#0aa1ed" text-color="#fff" active-text-color="#0f0"
                         @select="handleSelect">
                    <el-menu-item v-for="c in categoryArr" :index="c.id">{{c.name}}</el-menu-item>
                    <div style="float:right;position: relative;top:10px;right: 20px">
                        <el-input v-model="wd" placeholder="请输入搜索内容">
                            <!--  slot="append" 设置按钮嵌入到文本框里面 -->
                            <el-button slot="append" @click="search()" icon="el-icon-search"></el-button>
                        </el-input>
                    </div>
                </el-menu>
            </div>
        </el-header>
        <el-main style="width:1400px;margin:0 auto">
            <el-row gutter="20">
                <el-col span="18">
                    <el-carousel height="445px">
                        <!--走马灯开始-->
                        <el-carousel-item v-for="b in bannerArr">
                            <img :src="b.url" width="100%" height="100%">
                        </el-carousel-item>
                        <!-- 走马灯结束-->
                    </el-carousel>
                </el-col>
                <el-col span="6">
                    <el-card>
                        <h3 style="margin: 0">
                            <i style="font-weight: bold" class="el-icon-item">销量最高</i>
                        </h3>
                        <el-divider></el-divider>
                        <el-table :data="topArr">
                            <el-table-column type="index" label="排名"></el-table-column>
                            <el-table-column prop="title" label="商品名"></el-table-column>
                            <el-table-column prop="saleCount" label="销量"></el-table-column>
                        </el-table>
                    </el-card>
                </el-col>
            </el-row>
            <!--商品列表开始-->
            <el-row gutter="20">
                <el-col style="margin: 10px 0" span="6" v-for="p in productArr">
                    <el-card>
                        <a :href="'/detail.html?id='+p.id">
                            <img :src="p.url" width="100%">
                        </a>

                        <p style="font-size: 14px">
                            <a :href="'/detail.html?id='+p.id">
                                {{p.title}}
                            </a>
                        </p>
                        <p style="font-size: 12px">现价:{{p.price}} 原价:<s>{{p.oldPrice}}</s>
                            <span style="float:right">销量:{{p.saleCount}}件</span>
                        </p>
                    </el-card>
                </el-col>
            </el-row>
            <!--商品列表结束-->
        </el-main>
        <el-footer>
            <div style="background-image:url('../../../../../../Project/CoolShark/src/main/resources/static/imgs/wave.png'); height:95px"></div>
        </el-footer>
    </el-container>
</div>
</body>
<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                categoryArr:[],
                bannerArr: [],
                topArr: [],
                productArr: [],
                wd:""
            }
        },
        methods: {
            handleSelect(key, keyPath) {
                // console.log(key)
                // 可以是分类的id
                // 跳转到显示结果的页面,把分类的id传递
                location.href="/result.html?id="+key;
            },
            search(){
                if (v.wd.trim()==""){
                    v.$message.error("请输入要搜索的内容!");
                    return;
                }
                location.href="/result.html?wd="+v.wd;
            }
        },
        created:function (){
            // 获取所有分类信息
            axios.get("/category/select").then(function (response){
                v.categoryArr = response.data;
            })

            // 获取所有轮播图信息
            axios.get("/banner/select").then(function (response){
                v.bannerArr = response.data;
            })
            // 获取所有排行榜的数据
            axios.get("/product/selectTop").then(function (response){
                v.topArr = response.data;
            })

            // 获取所有商品数据
            axios.get("/product/selectIndex").then(function (response){
                v.productArr = response.data;
            })
        }
    })
</script>
</html>